<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>字符串类型</title>
    <script>
        function f1(){
            let s = " Hello World ";
            console.log("字符串长度:"+s.length);
            // 去除首尾的空格
            s = s.trim();
            console.log("字符串长度:"+s.length);
            console.log("大写:"+s.toUpperCase())
            console.log("小写:"+s.toLowerCase())
            console.log("获取索引位置为7的字符:"+s.charAt(7))
        }
        function f2(){
            // let s = "123";
            // let s = "123.45";
            // let s = "123abc";
            // let s = "123abc45";
            // let s = "123.45.67";
            let s = "a123";
            let num = parseInt(s);
            console.log(num)
        }
        function f3(){
            // let s = "123.45";
            // let s = "123.45.67";
            // let s = "123a.67";
            let s = "a123a.67";
            let num = parseFloat(s);
            console.log(num)
        }
        function f4(){
            let s = "Hello World,I am admin";
            // console.log(s.substring(7))
            console.log(s.substring(7,15))
        }
        function f5(){
            let s = "admin and jack and tom and lucy";
            console.log(s.length)
            console.log("and第一次出现的索引位置:"+s.indexOf("and"))
            console.log("and最后一次出现的索引位置:"+s.lastIndexOf("and"))
            console.log(s.replace("and","-"))
            console.log(s.replaceAll("and","-"))
        }
    </script>
</head>
<body>
<button onclick="f1()">常用方法</button><br>
<button onclick="f2()">转整数</button><br>
<button onclick="f3()">转小数</button><br>
<button onclick="f4()">截取字符串</button><br>
<button onclick="f5()">获取索引位置</button><br>
</body>
</html>